﻿Imports System.Data.OleDb

Public Class AddCar
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btn_Add_New_Car_Click(sender As Object, e As EventArgs) Handles btn_Add_New_Car.Click

        If F_Picture.HasFile Then
            F_Picture.SaveAs(Request.MapPath("Pictures") & "/" & F_Picture.FileName)

        End If



        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("MercedesConn").ConnectionString)
        Dim SqlString As String = "Insert into Mercedes(ModelName,ModelYear,CC,Condition,Colour,Registration,Price,ContactNumber,Picture,InfoURL,PostCode) Values (@f1,@f2,@f3,@f4,@f5,@f6,@f7,@f8,@f9,@f10,@f11)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", tb_ModelName.Text)
        cmd.Parameters.AddWithValue("@f2", tb_ModelYear.Text)
        cmd.Parameters.AddWithValue("@f3", tb_CC.Text)
        cmd.Parameters.AddWithValue("@f4", tb_Condition.Text)
        cmd.Parameters.AddWithValue("@f5", tb_Colour.Text)
        cmd.Parameters.AddWithValue("@f6", tb_Registration.Text)
        cmd.Parameters.AddWithValue("@f7", tb_Price.Text)
        cmd.Parameters.AddWithValue("@f8", tb_ContactNumber.Text)
        cmd.Parameters.AddWithValue("@f9", "Pictures/" & F_Picture.FileName)
        cmd.Parameters.AddWithValue("@f10", tb_InfoURL.Text)
        cmd.Parameters.AddWithValue("@f11", tb_PostCode.Text)


        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        Response.Redirect("List.aspx")





    End Sub
End Class